package com.atguigu.Threads;

/**
 * 1.默认的线程优先级为5，共有10个档次
 * 2.getPriority():得到当前线程的优先级
 * 3。setPriority(int n):设置当前线程的优先级
 * 4.优先级只是抢到cpu的概率大一点
 *
 * @author xiaoqi
 * @data 2021/04/02 14:49
 */
public class ThreadPriority {
    public static void main(String[] args) {
        MyThread t1 = new MyThread();
        t1.setPriority(Thread.MAX_PRIORITY);
        new MyThread(){
            @Override
            public void run() {
                Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                Thread.currentThread().setName("子线程二");
                for (int i = 0; i < 100; i++) {
                    if(i % 2 == 0){
                        System.out.println(Thread.currentThread().getPriority() + ":" + i);
                    }
                }
            }
        }.start();
        t1.start();
        System.out.println(t1.getPriority());
    }

}
